package com.duan.SpringbootMybatis.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import net.minidev.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.duan.SpringbootMybatis.domain.User;
import com.duan.SpringbootMybatis.page.PageInfo;
import com.duan.SpringbootMybatis.service.UserService;
import com.duan.SpringbootMybatis.util.DataUtil;
import com.github.pagehelper.Page;

@Controller
@RequestMapping("/user")
public class UserController {

	@Autowired
	UserService userService;
	/**
	 * 
	* @Title: queryUserInfo 
	* @Description: TODO(查询用户信息) 
	* @param @param request
	* @param @param model
	* @param @return
	* @return String 
	* @author duanws
	* @date 2017年12月14日上午10:11:27
	* @throws
	 */
	@RequestMapping("queryUserInfo")
	public String queryUserInfo(HttpServletRequest request,ModelMap model){
		List<User> userList = this.userService.queryUserInfo(new User("1","22","",null,null));
		if(userList == null || userList.size()<1){
			return "啥也没有";
		}
		String returnMsg = DataUtil.arrayToJson(userList);
		model.addAttribute("returnMsg", returnMsg);
		return "user/userInfo";
	}
	/**
	 * 
	* @Title: queryUserPage 
	* @Description: TODO(分页查询用户信息) 
	* @param @param request
	* @param @param model
	* @param @return
	* @return String 
	* @author duanws
	* @date 2017年12月14日上午10:11:13
	* @throws
	 */
	@RequestMapping("queryUserPage")
	public String queryUserPage(HttpServletRequest request,ModelMap model){
		Page<User> userPage = this.userService.queryUserPage(new User(), 1, 2);
		PageInfo<User> resultPage = new PageInfo<User>(userPage); 
		model.addAttribute("resultPage", resultPage);
		model.addAttribute("returnMsg", "测试用户分页");
		return "user/userPage";
	}
	
}
